<template>
	<view class="submissionreport">
		<!-- 顶部导航 -->
		<diyNavBar value='举报维权'></diyNavBar>
		<view class="taskinput">
			<text class="title">任务编号</text>
			<input type="text" v-model="setData.task_id" placeholder="请输入任务编号"/>
		</view>
		<view class="textarea">
			<view class="title">举报理由</view>
			<textarea v-model="setData.context" maxlength="200" placeholder="请输入举报理由" />
			<text class="num">{{num}}/200</text>
		</view>
		<view class="textarea addimage">
			<view class="title">上传截图</view>
			<view class="box">
				<view class="imagebox" v-if="setData.image.length" v-for="(v,n) in setData.image" :key='n'>
					<image :src="$util.img(v)" mode="widthFix"></image>
					<text class="iconfont icon-jiufuqianbaoicon08" @click="deletes(n)"></text>
				</view>
				<block v-if="imgPreloadJudge">
					<view class="image preload" v-for="(item,index) in imgPreload" :key="index + 's'">
						<image src="../../static/img/04.gif" mode="widthFix"></image>
					</view>
				</block>
				<view class="image" @click="addImg">
					<text class="iconfont icon-tianjiatianchong"></text>
				</view>
			</view>
		</view>
		<button type="default" class="btn" @click="setPost">提交举报</button>
	</view>
</template>

<script>
	import diyNavBar from '../../component/diy-nav/diy-navbar.vue'
	export default{
		components:{diyNavBar},
		data(){
			return {
				num:0,
				setData:{
					context:'',
					image:[],
					task_id:''
				},
				imgPreload:[],//图片预加载
				imgPreloadJudge:false
			}
		},
		onLoad(option) {
			
		},
		methods:{
			addImg(){
				this.$util.selectImage({
					num:6,
					success:(res)=>{
						if(!res.judge){
							this.imgPreloadJudge = true;
							this.imgPreload = res.data;
						}else{
							JSON.parse(res.data).data.forEach(item=>{
								if(this.setData.image.length<6){
									this.setData.image.push(item.filepath);
									this.imgPreloadJudge = false
								}else{
									uni.showToast({title:'最多添加六张',icon:'none'})
								}
							})
						}
					}
				})
			},
			//举报提交
			setPost(){
				this.$http.sendrequest('/reports/AddReports',this.setData,{
					tokenJudge:true
				}).then(res=>{
					if(res.code == 1) {
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta: 1
							});
						},1000)
					}
				})
			},
			deletes(index){
				this.setData.image.splice(index,1)
			}
		},
		watch:{
			setData(){
				this.num = this.setData.context.split('').length;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.submissionreport{
		min-height: 100vh;
		background: $uni-content-background-color;
	}
	.taskinput{
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		height: 120rpx;
		border-bottom: 2rpx solid rgba(0,0,0,.02);
		background: #FFFFFF;
		.title{
			font-size: 28rpx;
			margin-right: 80rpx;
		}
		input{
			width: 60%;
			font-size: 28rpx;
		}
	}
	.textarea{
		padding: 40rpx 30rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		position: relative;
		border-bottom: 2rpx solid rgba(0,0,0,.02);
		background: #FFFFFF;
		.title{
			margin-bottom: 50rpx;
		}
		textarea{
			width: 100%;
			height: 200rpx;
			font-size: 28rpx;
			line-height: 1.8;
		}
		.num{
			position: absolute;
			right: 42rpx;
			bottom: 54rpx;
		}
	}
	.addimage{
		min-height: 420rpx;
		border-bottom: 2rpx solid rgba(0,0,0,.02);
		background: #FFFFFF;
		.title{
			margin-bottom: 36rpx;
		}
		.box{
			display: flex;
			flex-wrap: wrap;
			.image{
				width: 240rpx;
				height: 240rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #EFF2F7;
				border-radius: 16rpx;
				margin: 10rpx 10rpx 0 0;
				image{
					width: 100%;
					height: 100%;
					margin: 10rpx 10rpx 0 0;
				}
				.icon-tianjiatianchong{
					font-size: 60rpx;
					color: #FF6F30;
				}
			}
			.preload{
				margin: 10rpx 10rpx 0 0;
			}
			.imagebox{
				position: relative;
				.icon-jiufuqianbaoicon08{
					font-size: 38rpx;
					color: #FF6F30;
					position: absolute;
					top: -8rpx;
					right: -4rpx;
				}
				image{
					width: 240rpx;
					max-height: 240rpx;
					border-radius: 16rpx;
					margin: 10rpx 10rpx 0 0;
				}
			}

		}
	}
	.btn{
		margin: 60rpx;
		height: 90rpx;
		color: #FFFFFF;
		background: #FF6F30;
		font-size: 32rpx;
		border-radius: 90rpx;
	}
</style>
